From 663c2bde8bba3736640f8785368fff3821e8c91d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 18 Sep 2005 20:27:37 +0000 Subject: [PATCH] memory sugar --- ChangeLog | 5 +++++ babl/babl-memory.c | 14 +++++++++++++- babl/babl-memory.h | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14e1646..20f7585 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-09-18 Øyvind Kolås + + * babl/babl-memory.[ch]: (babl_free), (babl_realloc): made babl_free + variadic, and added the potential for a clearing realloc. + 2005-09-12 Øyvind Kolås * tests/conversions.c: (test_init): code simplification. diff --git a/babl/babl-memory.c b/babl/babl-memory.c index b152f85..82719ae 100644 --- a/babl/babl-memory.c +++ b/babl/babl-memory.c @@ -131,9 +131,13 @@ babl_dup (void *ptr) /* Free memory allocated by a babl function (note: babl_free * will complain if memory not allocated by babl is passed.) + * + * Note: the function is made variadic to be a legal callback + * function in some circumstances. */ void -babl_free (void *ptr) +babl_free (void *ptr, + ...) { if (!ptr) return; @@ -171,7 +175,15 @@ babl_realloc (void *ptr, } else if (babl_sizeof (ptr) < size) { +#ifdef USE_REALLOC_CLEAR + /* not needed yet by babl, if aviodable, preferred, since + * it has performance hits where it isn't wanted, a special + * function might be better when needd. + */ + ret = babl_calloc (size, 1); +#else ret = babl_malloc (size); +#endif memcpy (ret, ptr, babl_sizeof (ptr)); babl_free (ptr); reallocs++; diff --git a/babl/babl-memory.h b/babl/babl-memory.h index 170e566..fbb311b 100644 --- a/babl/babl-memory.h +++ b/babl/babl-memory.h @@ -25,7 +25,8 @@ void babl_set_free (void (*free) (void *ptr)); int babl_memory_sanity (void); void * babl_malloc (size_t size); -void babl_free (void *ptr); +void babl_free (void *ptr, + ...); void * babl_calloc (size_t nmemb, size_t size); void * babl_realloc (void *ptr, -- 2.30.2